#ifndef __MYIIC_H__
#define __MYIIC_H__

#include "stm32f10x.h"
#include "gpio.h"

#define SCLK GPIO_Pin_0
#define SDAT GPIO_Pin_1

void iic_delay_us(uint16_t dly_cnt);
void iic_delay_ms(uint16_t dly_cnt);
#define delay_us iic_delay_us
#define delay_ms iic_delay_ms



//下面需更改成为自己使用的开发板类型
//IO方向设置
#define SDA_OUT()	gpio_config_out(SDAT)//SDA设置为输出
#define SDA_IN()	gpio_config_in(SDAT)//SDA设置为输入

//IO操作函数	 
#define SCL0_HIGH()		  gpio_set(SCLK,1)//SCL置高
#define SCL0_LOW()		  gpio_set(SCLK,0)//SCL置低
#define SDA0_HIGH()		  gpio_set(SDAT,1)//SDA置高
#define SDA0_LOW()		  gpio_set(SDAT,0)//SDA置低
#define SDA0_READ()		  gpio_get_input(SDAT)//获取SDA电平状态

//IIC所有操作函数
void IIC_Init(void);                //初始化IIC的IO口				 
void IIC_Start(void);				//发送IIC开始信号
void IIC_Stop(void);	  			//发送IIC停止信号
void IIC_Send_Byte(uint8_t txd);	//IIC发送一个字节
uint8_t IIC_Read_Byte(unsigned char ack);//IIC读取一个字节
uint8_t IIC_Wait_Ack(void); 		//IIC等待ACK信号
void IIC_Ack(void);					//IIC发送ACK信号
void IIC_NAck(void);				//IIC不发送ACK信号

void IIC_Write_One_Byte(uint8_t daddr,uint8_t addr,uint8_t data);
uint8_t IIC_Read_One_Byte(uint8_t daddr,uint8_t addr);	  


#define  Soft_I2C_READY		              0x00
#define  Soft_I2C_BUS_BUSY	            0x01
#define  Soft_I2C_BUS_ERROR	            0x02
//#define  I2C_Direction_Transmitter      0x00
//#define  I2C_Direction_Receiver         0x01

int Sensors_I2C_ReadRegister(unsigned char Address,
							 unsigned char RegisterAddr, 
                             unsigned short RegisterLen,
							 unsigned char *RegisterValue);
int Sensors_I2C_WriteRegister(unsigned char Address,
							  unsigned char RegisterAddr, 
                              unsigned short RegisterLen,
							  const unsigned char *RegisterValue);
#endif
